﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ajeelee.Core.Database;
using Ajeelee.Core.Utils;
using AiLuWeb.Business;
using AiLuWeb.Model;
using AiLuWeb.WebSite.Code;

namespace AiLuWeb.WebSite
{
    public partial class newslist : PageBase
    {
        protected int pid;
        protected string title, cname;
        Hashtable table = new Hashtable();
        protected IList<News> newList = new List<News>();
        INewsBusiness newBll = new NewsBusinessFactory().CreateNewsBusiness();
        protected PageStructure ps = new PageStructure() { CurrPage = 1, PageSize = 6 };

        protected void Page_Load(object sender, EventArgs e)
        {
            pid = QueryParamInt32("id");
            title = QueryParam("title");
            // 接收参数
            if (QueryParamInt32("page") > 1)
            {
                ps.CurrPage = QueryParamInt32("page");
            }

            try
            {
                // 读取分页数据
                if (pid > 0)
                    table.Add(NewsHash.CId, pid);
                if (title.IsNotNullAndEmpty())
                    table.Add(NewsHash.Title, Function.SafeSqlLiteral(title));
                newList = newBll.GetAllNewsByPage(table, ps);
                this.pager.PageStruct = ps;

                var citem = Utility.GetNewsClass().FirstOrDefault(c => c.Id == pid);
                if (citem != null)
                {
                    cname = citem.Name;
                }
            }
            catch (Exception ex)
            {
                Function.WriteErrorLog(ex);
            }
        }
    }
}